// pages/cls/complaint/sacnList/index.js
var basePage = require('../../../../common/BasePage')
var baseList = require('../../../../common/BaseList')
Page({
  behaviors: [basePage, baseList],
  /**
   * 页面的初始数据
   */
  data: {
    reqUrl: "/home/afterSaler/index",
    userId: ''
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad(options) {
    this.req_items()
  },
  onDelete(e) {
    var item = e.currentTarget.dataset.item
    var that = this
    wx.showModal({
      title: '提示',
      content: '请确定是否删除扫码售后人员',
      complete: (res) => {
        if (res.confirm) {
          that.request({
            url: that.data.host + "/home/afterSaler/delete",
            data: {
              after_saler_id: item.after_saler_id
            },
            method: "POST"
          }, res => {
            that.data.current_page = 0;
            that.req_items()
          })
        }
      }
    })
  },
  onAdd() {
    this.request({
      url: this.data.host + "/home/afterSaler/create",
      data: {
        saler_id: this.data.userId
      },
      method: "POST"
    }, res => {
      wx.showToast({
        title: '添加成功',
        icon: "none"
      })
      this.setData({
        showAdd: false,
        userId: ''
      })
      this.data.current_page = 0;
      this.req_items()
    })
  },
  //扫描二维码
  onScan() {
    var that = this
    wx.scanCode({
      success(res) {
        console.log("扫码成功", res)
        var scene = res.result
        var arr = scene.split("|")
        //来源:订单ID:订单商品ID
        console.log("扫二维码拆分", arr)
        if (arr.length > 0) {
          that.setData({
            order_id: arr[1],
            order_pid: arr[2],
            
          })
          that.getOrder()
        } else {
          wx.showToast({
            title: '扫码失败',
            icon: "none"
          })
        }
      }
    })
  },
  getOrder(){
    this.request({
      url:this.data.host+"/home/order/complaintDetail",
      data:{
        order_id:this.data.order_id,
        order_pid:this.data.order_pid
      }
    },res=>{
        var info=res.data
        info.thumb=this.get_thumb(info.product_img)
        info.order_product_id=this.data.order_pid
        info.order_id=this.data.order_id
        wx.navigateTo({
          url: "/pages/cls/complaint/Index",
          success: function (obj) {
            //传递产品数据
            obj.eventChannel.emit('pdcData',info)
          }
        })
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

})